
import { v4 as uuidv4 } from 'uuid'

class Base {
  __advClass = true;
  uuid: string = uuidv4()
  loading: boolean = false;
  onDefaultAction: number = Date.now();
  onInfoUpdateAction: number = Date.now();
  auth: any = {};
  constructor() {
    return this;
  }





  init(options: any = {}) {
    for (let i in options) {
      (this as any)[i] = options[i]
    }
  }


  query() {
    // const clone: any = {};
    // for (let key in this) {
    //   const value = this[key] as any;
    //   // 基于Base类
    //   if(value instanceof Base) {

    //   }

    // }
  }

  isEmpty() {
    return true;
  }


  reset() {
    this.uuid = uuidv4();
  }



  // 克隆类
  clone() {
    const clone = Object.create(this);
    function createCloneValue(value: any): any {
      if (value instanceof Base) return value.clone()
      let cloneValue: any = value;
      if (value && typeof value == 'object') {
        if (Array.isArray(value)) {
          return value.map(item => {
            return createCloneValue(item)
          })
        } else {
          const clone: any = {};
          // console.log(value, 'value');
          Object.keys(value).map(key => {
            clone[key] = createCloneValue(value[key])
          });
          return clone;
        }

      } else if (typeof value == 'function') {
        return cloneValue
      } else {
        return cloneValue
      }
    }

    for (let key in this) {
      clone[key] = createCloneValue(this[key]);
    }

    return clone;
  }
}

export default Base
